package com.qk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.mapper.RoleMapper;
import com.qk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageResult<Role> page(String name, String label, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Role> roleList = roleMapper.page(name,label);
        PageInfo<Role> pageInfo = new PageInfo<Role>(roleList);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void addRole(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.addRole(role);
    }

    @Override
    public Role selectById(Integer id) {
        Role role = roleMapper.selectById(id);
        return role;
    }

    @Override
    public void updateRole(Role role) {
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.updateRole(role);
    }

    @Override
    public List<Role> roleList() {
        return roleMapper.roleList();
    }

    @Override
    public void deleteRoleById(Integer id) {
        roleMapper.delectRoleById(id);
    }
}
